package com.goti.nettyClient.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import com.goti.nettyClient.Dispatcher.NettyClientDispatcher;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    private NettyClientDispatcher dispatcher;

    @GetMapping(value = "sendMsg")
    public Object sendMsg(){
        JSONObject object = new JSONObject();
        object.put("playerId","20190101");
//        object.put("userName",input.get("userName"));




        TimeInterval timer = DateUtil.timer();


        //获取玩家info by id
        dispatcher.sendMsg("6000", "0", "0", object.toString());
        ChannelHandlerContext ctx = dispatcher.getChannelHandlerContext();




        HttpUtil.get("192.168.3.111:8082/player/get", object);
        System.out.println("短连接花费时间"+timer.interval());

        return null;
    }

}
